#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
	int n, m, x;
	cin >> n >> m;
	deque<int> a, b;
	while (n--) {
		cin >> x;
		a.push_front(x);
	}
	while (m--) {
		cin >> x;
		b.push_front(x);
	}

	int ans = 0;
	while (!a.empty() || !b.empty()) {
		if (a.front() > b.front()) {
			int t = b.front();
			b.pop_front();
			t += b.front();
			b.pop_front();
			b.push_front(t);
			ans++;
		} else if (a.front() < b.front()) {
			int t = a.front();
			a.pop_front();
			t += a.front();
			a.pop_front();
			a.push_front(t);
			ans++;
		} else {
			a.pop_front();
			b.pop_front();
		}
	}
	cout << ans;
	return 0;
}
